package com.rrd.dw.mr.gzip.kafka;

import com.ucredit.babel.common.model.BaseModel;
import com.ucredit.babel.common.model.RecordType;
import com.ucredit.babel.common.model.jitui.JiTuiMobileStatusData;
import com.ucredit.babel.common.model.jitui.JiTuiMobileStatusRecord;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper.Context;

import java.io.IOException;

/**
 * 极推在网状态
 *
 * @author renzhanzheng
 */

public class JiTuiMobileStatusParse extends  ParseBase {
    private Text val = new Text();
    private Text key = new Text();

    /**
     * 极推在网状态
     *
     * @param model
     * @throws IOException
     * @throws InterruptedException
     */
    @Override
    public boolean parseJob(Context context, BaseModel<?> model, String successful) throws IOException, InterruptedException {
        JiTuiMobileStatusRecord obj = (JiTuiMobileStatusRecord)model;
        JiTuiMobileStatusData data = obj.getData();

        StringBuilder sb = getBaseInfo(obj, successful);
        //响应说明
        sb.append(data.getMsg() == null ? "" : data.getMsg()).append(CRT001);
        //状态码
        sb.append(data.getCode() == null ? "" : data.getCode()).append(CRT001);
        //是否收费
        sb.append(data.getFee()).append(CRT001);
        //号码当前归属的运营商
        sb.append(data.getProvider() == null ? "" : data.getProvider()).append(CRT001);
        //状态
        sb.append(data.getStatus() == null ? "" : data.getStatus()).append(CRT001);

        key.set(getKey());
        val.set(sb.toString().replace("\n", " ").replace("\r", " "));
        context.write(key, val);
        return true;
    }

    @Override
    public String getTableName() {
        return "kafka_babel_jitui_onlinestatus_inc";
    }

    @Override
    public String getType() {
        return RecordType.JITUI_MOBILESTATUS_RECORD.toString();
    }

    @Override
    public String getComment() {
        return "极推在网状态";
    }
}
